package com.wei.frame.ui.widget;

import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import com.wei.frame.R;
import com.wei.frame.databinding.DialogCommonBinding;

/**
 * 作者:赵若位
 * 时间:2021/6/25 16:58
 * 功能:基础的Dialog
 */
public class CommonDialog {


    public static AlertDialog createDialog(Context context, @Nullable String title, @Nullable String message,
                                           @Nullable String cancel, @Nullable String confirm) {
        Resources resources = context.getResources();
        DialogCommonBinding binding = DialogCommonBinding.inflate(LayoutInflater.from(context));
        AlertDialog dialog = new AlertDialog.Builder(context, R.style.BaseCommonDialogStyle)
                .setView(binding.getRoot())
                .create();
        binding.tvPrompt.setText(TextUtils.isEmpty(title) ? resources.getString(R.string.prompt) : title);
        if (TextUtils.isEmpty(message)) {
            binding.tvDesc.setVisibility(View.GONE);
        } else {
            binding.tvDesc.setText(message);
        }
        binding.tvCancel.setText(TextUtils.isEmpty(title) ? resources.getString(R.string.cancel) : cancel);
        binding.tvConfirm.setText(TextUtils.isEmpty(title) ? resources.getString(R.string.confirm) : confirm);
        dialog.show();
        return dialog;
    }


}
